-
Notifications
You must be signed in to change notification settings - Fork 19.2k
fix: tool decorator pylance type hints #33203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: tool decorator pylance type hints #33203
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. |
CodSpeed Performance ReportMerging #33203 will not alter performanceComparing
|
@krishvsoni the PR looks very AI generated. This is a bit of a problem for a lot of OSS maintainers these days since it's not clear whether the contributor has taken time to understand the actual changes in the code, which for a maintainer means that we have to re-do all the work from scratch + have an overhead on communication / coordination on a PR. Take a look at the existing PR it has a lot of linting issues etc |
@eyurtsev Thank you for the feedback, I understand your concern. I want to clarify that while I did refer to the previous PR for context, I carefully reviewed the underlying code and intentionally expanded on it to improve overload coverage and type safety. My goal was to make this change maintainable and pass strict type checks without altering runtime behavior. I'm happy to walk through any part in more detail or adjust areas that seem unclear or too automated. |
- Reformat imports to multi-line format for readability - Remove docstrings from @overload functions (per D418) - Remove unnecessary ellipsis literals (per PIE790) - Fix blank line formatting between overloads and main function All linting checks now pass: ruff check, ruff format, mypy
Fix Pylance "Type of 'tool' is partially unknown" Error
Title:
fix(core): enhance tool decorator type annotations for pylance strict mode
Fixes #33019
Description
This PR resolves the Pylance type checking error where importing the
tool
decorator in strict mode would show "Type of 'tool' is partially unknown". The issue was caused by complex overloaded function signatures that weren't properly typed for static analysis tools like Pylance.Solution
Enhanced the type annotations in
libs/core/langchain_core/tools/convert.py
:Added TypeVar imports for better type inference:
Improved overload signatures with:
Callable[..., Any]
vsCallable
)Added comprehensive test to prevent regressions and verify all decorator patterns work correctly
Comparison to Previous PR #33020
This solution is significantly better than the previous attempt because:
Testing
@tool
(simple decorator)@tool("custom_name")
(named decorator)@tool(description="...")
(keyword args)@tool(description="...", return_direct=True)
(multiple kwargs)tool(function)
(direct conversion)Key Benefits
The enhanced type annotations provide clearer type information to static analysis tools while maintaining full backward compatibility and following LangChain's development guidelines.
Dependencies
None - only type annotation improvements to existing code.
Issue
Fixes #33019